<#include "custom.include">
<#assign className = table.className>   
<#assign classNameLower = className?uncap_first>   
package ${basepackage}.${subpackage}.action;

import java.util.List;
import java.util.jar.Attributes.Name;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.banxue.entity.${className};
import com.banxue.service.${className}Service;
import com.banxue.utils.AppToken;
import com.banxue.utils.AppTokenManager;
import com.banxue.utils.CommonUtils;
import com.banxue.utils.Constants;
import com.banxue.utils.ReturnMsg;

@Controller
@RequestMapping(value = "/app")
public class ${className}Action extends BaseAction {
	private static Logger logger = LoggerFactory.getLogger(${className}Action.class);

	@Autowired
	private ${className}Service ${classNameLower}Service;

	@RequestMapping(value = "a/${classNameLower}/add", method = RequestMethod.POST)
	public void add${className}(Stirng name, HttpServletResponse response) {
		if(StringUtils.isNoneBlank(name)){
			${className} ${classNameLower} = new ${className}();
			${classNameLower}.setCreateTime(CommonUtils.getCurrentDate());
			${classNameLower}Service.insert(${classNameLower});
			logger.info("create ${classNameLower}:");
			ReturnMsg.writeMsg(ReturnMsg.success, ${classNameLower}.getId(), response);
		}else{
			ReturnMsg.writeMsg(ReturnMsg.paramError, response);
		}
	}

	@RequestMapping(value = "a/${classNameLower}/get", method = RequestMethod.POST)
	public void get${className}(Integer id, HttpServletResponse response) {
		if(id != null && id > 0){
			${className} ${classNameLower} = new ${className}(id);
			${classNameLower} = ${classNameLower}Service.findById(${classNameLower});
			ReturnMsg.writeMsg(ReturnMsg.success, ${classNameLower}, response);
		}else{
			ReturnMsg.writeMsg(ReturnMsg.paramError, response);
		}
	}

	@RequestMapping(value = "a/${classNameLower}/list", method = RequestMethod.POST)
	public void listMy${className}(HttpServletResponse response) {
		if(appToken.getUserId() > 0){
			${className} ${classNameLower} = new ${className}();
			${classNameLower}.setUserId(appToken.getUserId());
			List<${className}> ${classNameLower}s = ${classNameLower}Service.query(${classNameLower});
			ReturnMsg.writeMsg(${classNameLower}s, response);
		}else{
			ReturnMsg.writeMsg(ReturnMsg.paramError, response);
		}
	}

	@RequestMapping(value = "a/${classNameLower}/edit", method = RequestMethod.POST)
	public void edit${className}(Integer id, String name, HttpServletResponse response) {
		if(id != null && id > 0){
			${className} ${classNameLower} = new ${className}(id);
			${classNameLower}.setUpdateTime(CommonUtils.getCurrentDate());
			${classNameLower}Service.update(${classNameLower});
			ReturnMsg.writeMsg(ReturnMsg.success, response);
		}else{
			ReturnMsg.writeMsg(ReturnMsg.paramError, response);
		}
	}

	@RequestMapping(value = "a/${classNameLower}/delete", method = RequestMethod.POST)
	public void delete${className}(Integer id, HttpServletResponse response) {
		if(id != null && id > 0){
			${className} ${classNameLower} = new ${className}(id);
			${classNameLower}Service.delete(${classNameLower});
			ReturnMsg.writeMsg(ReturnMsg.success, response);
		}else{
			ReturnMsg.writeMsg(ReturnMsg.paramError, response);
		}
	}
}
